package com.speaktoitcookbook.dao.proxy;

import java.sql.Connection;
import java.util.List;

import com.speaktoitcookbook.bean.UserInfo;
import com.speaktoitcookbook.dao.IUserInfoDao;
import com.speaktoitcookbook.dao.impl.UserInfoDaoImpl;
import com.speaktoitcookbook.db.Database;

/**
 * 用户信息数据操作代理类
 * 
 * @author 杨强
 * 
 */
public class UserInfoDaoProxy implements IUserInfoDao {
    private Connection conn;
    private IUserInfoDao userInfoDao;

    public UserInfoDaoProxy() {
        this.conn = Database.getInstance().getConnection();
        this.userInfoDao = new UserInfoDaoImpl(conn);
    }

    @Override
    public boolean doUpdate(UserInfo userInfo) {
        boolean result = false;
        if (null != userInfo) {
            result = userInfoDao.doUpdate(userInfo);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public UserInfo getUserInfo(String userID) {
        UserInfo result = null;
        if ((null != userID) && (!userID.isEmpty())) {
            result = userInfoDao.getUserInfo(userID);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<UserInfo> getUserInfo(Object... params) {
        List<UserInfo> result = null;
        if (null != params) {
            result = userInfoDao.getUserInfo(params);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public long getUserCount(Object... params) {
        long result = 0;
        if (null != params) {
            result = userInfoDao.getUserCount(params);
        }
        Database.close(conn);
        return result;
    }
}
